package com.cxs.handler;

import com.cxs.enums.HospitalErrorResultEnum;
import com.cxs.exception.HospitalException;
import com.cxs.vo.Result;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/*
 * @Author:cxs
 * @Date:2021/10/15  15:11
 * @Version 1.0
 * @Motto:放下杂念,只为迎接明天更好的自己
 * */
@RestControllerAdvice
public class HospitalExceptionHandler {

    @ExceptionHandler({IncorrectCredentialsException.class, UnknownAccountException.class})
    public Result credentialsException(){
        return Result.failare(HospitalErrorResultEnum.USERNAME_PASSWORD_ERROR);
    }

    @ExceptionHandler(value = HospitalException.class)
    public Result authHospitalException(HospitalException e){
        return Result.failare(e.getCode(),e.getMessage());
    }
}
